package com.foreknow.test_JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCUtilDemo {
    public static void main(String[] args) {
        try {
            //
            Class.forName("com.mysql.jdbc.Driver");
            //
            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_database", "root", "KCZ20021115");
            //
            Statement statement = connection.createStatement();
            int isRight = statement.executeUpdate("INSERT INTO admin (name,pass) VALUES('rose','qwertyuio')");
            if (isRight == 1) {
                System.out.println("success");
            } else {
                System.out.println("error");
            }
            int isRight1 = statement.executeUpdate("UPDATE admin SET name = 'tom' WHERE id=8");
            if (isRight1 == 1) {
                System.out.println("success");
            } else {
                System.out.println("error");
            }
            int isRight2 = statement.executeUpdate("DELETE FROM admin WHERE id = 1");
            if (isRight2 == 1) {
                System.out.println("success");
            } else {
                System.out.println("error");
            }
            statement.close();
            connection.close();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }
}
